# -*- coding: utf-8 -*-
'''
Created on 2011-7-28

@author: Johnny
'''
import unittest
import time

from selenium import selenium
from resultdeal import Result


class CoreTest(unittest.TestCase):


    def __init__(self):
        pass
    
    def setUp(self, host, port, browser, destination):
        '''
        '''
        self.host = host
        self.selenium = selenium(host, port, browser, destination)
        self.selenium.start()
        
    def shutDownServer(self):
        '''
        Shut down selenium server after test finished.
        '''
        self.selenium.shut_down_selenium_server()
    
    def step_init(self, steps):
        print 'core -- step_init:' + str(steps)
        for step in steps:
            step.set_up(self.selenium)
    
    def tearDown(self):
        self.selenium.stop()
        
    def test(self, case):
        print 'core -- test '
        time_stamp = time.strftime('%Y%m%d_%H%M', time.localtime())
        self.case = case
        case_name = self.case.pop(0)
        self.step_init(self.case)        
        step_index = 0

        try:
            for step in case:
                step.run()
                step_index = step_index + 1
        except:    
            pass   
        
        self.case.insert(0, case_name)
        self.case.insert(1, time_stamp)
        Result.deal_result(self.case)
    


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()